package org.advanced.pipeline;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

/**
 * @author John.zhang
 * @version Id: PipelineSet, v 1.0 2020/12/23 18:01 ZhiYong Exp $
 * 利用管道提高写入效率,对实时性和准确性要求不高
 */
public class PipelineSet {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("10.181.144.255", 6379);
        Pipeline pipelined = jedis.pipelined();
        long t1 = System.currentTimeMillis();
        int max = 1000;
        for (int i=0; i < max; i++) {
            pipelined.set("batch"+i,""+i);
        }
        pipelined.syncAndReturnAll();
        long t2 = System.currentTimeMillis();
        System.out.println("耗时："+(t2-t1)+"ms");
    }
}
